//
//  Vector.h
//  GSEngine
//
//  Created by Гукун Александр on 1/23/14.
//  Copyright (c) 2014 SNK. All rights reserved.
//

#ifndef __GSEngine__Vector__
#define __GSEngine__Vector__

#include <iostream>
#include <math.h>

namespace GSEngine
{
    template <typename T>
    struct vec2
    {
        typedef vec2<T> vec2T;
        T x,y;
        vec2():x(0),y(0) {}
        vec2(T newX, T newY):x(newX),y(newY) {}
        vec2(T oneValue):x(oneValue),y(oneValue) {}
        vec2T& operator=(vec2T newVec)
        {
            x = newVec.x;
            y = newVec.y;
            return *this;
        }
        vec2T& operator=(T oneValue)
        {
            x = y = oneValue;
            return *this;
        }
        T length()
        {
            return sqrtf(x * x + y * y);
        }
        void normalize()
        {
            (*this)/=length();
        }
        void normalize(T newLength)
        {
            (*this)/=length();
            (*this)*=newLength;
        }
        vec2T& operator*=(T value)
        {
            x *= value;
            y *= value;
            return (*this);
        }
        vec2T operator*(T value)
        {
            return vec2T(x*value, y*value);
        }
        vec2T& operator/=(T value)
        {
            x /= value;
            y /= value;
            return (*this);
        }
        vec2T operator/(T value)
        {
            return vec2T(x/value, y/value);
        }
        vec2T operator-(vec2T newVec)
        {
            return vec2T(x - newVec.x, y - newVec.y);
        }
};

typedef vec2<float> vec2f;
typedef vec2<double> vec2d;
typedef vec2<int> vec2i;
typedef vec2<unsigned int> vec2ui;
typedef vec2<unsigned short> vec2us;

}

#endif /* defined(__GSEngine__Vector__) */
